<?php
class Student_Model extends CI_Model {
	function __construct() {
		parent::__construct();
	}

	function get_stu_list($condition) {

	}

	function get_stu_detail($stu_id, $detail = NULL) {
		if($detail == NULL) $detail = "*";
		else $detail = implode($detail, ",");
		$query = $this->db->query("SELECT ".$detail."FROM wb_student WHERE stu_id = ".$stu_id);
		if($query->num_rows() > 0) {
			return $query->row_array();
		}
		else return array();
	}

	function add_stu($post) {
		$query = $this->db->insert("wb_student_info", $post);
		if($query == FALSE) return -1;
		$relation = array("sch_id" => $post['sch_id'],
			"province" => $post['province'],
			"hlp_id" => 0,
			"stu_status" => 0,
			"hlp_status" => 0);
		$query = $this->db->insert("wb_relation", $relation);
		if($query == TRUE) return 0;
		else return -1;
	}

	function edit_stu($stu_id, $post) {

	}

	function delete_stu($stu_id) {
		$query = $this->db->query("SELECT stu_status FROM wb_relation WHERE stu_id = ".$stu_id);
		if($query->num_rows() == 0) return -1;
		$res = $query->row_array();
		if($res["stu_status"] != 1 && $res["stu_status"] != 5) return 1;
		$query = $this->db->query("DELETE FROM wb_relation WHERE stu_id = ".$stu_id);
		if($query == FALSE) return -1;
		$query = $this->db->query("DELETE FROM wb_student_info WHERE stu_id = ".$stu_id);
		if($query == FALSE) return -1;
		$query = $this->db->query("DELETE FROM wb_student_news WHERE stu_id = ".$stu_id);
		if($query == FALSE) return -1;
		return 0;
	}
}
/* End of file student_model.php */